﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JLL.China.Infrastructure.Repositories.ListingFloorPlan
{
    public class ListingFloorPlanRepository : SQLRepositoryBase<Model.ListingFloorPlan, int>, IListingFloorPlanRepository
    {
        public override Model.ListingFloorPlan FindBy(int key)
        {
            throw new NotImplementedException();
        }

        public override IList<Model.ListingFloorPlan> FindAll()
        {
            throw new NotImplementedException();
        }

        protected override void PersistNewItem(Model.ListingFloorPlan item)
        {
            throw new NotImplementedException();
        }

        protected override void PersistUpdatedItem(Model.ListingFloorPlan item)
        {
            throw new NotImplementedException();
        }

        protected override void PersistDeletedItem(Model.ListingFloorPlan item)
        {
            throw new NotImplementedException();
        }


        public int Deleted(decimal? id)
        {
            return DataContext.sp_listingfloorplan_delete(id);
        }
        public decimal Create(Model.ListingFloorPlan item)
        {
            return DataContext.sp_listingfloorplan_create(item.TypeModel, item.NoUnit, item.FloorPlanImg, item.ListingFID,
                                                  item.LanguageFID, item.ListingFloorPlan_ID);
        }

        public decimal Update(Model.ListingFloorPlan item)
        {
            return DataContext.sp_listingfloorplan_update(item.TypeModel, item.NoUnit, item.FloorPlanImg, item.ListingFID,
                                                  item.LanguageFID, item.ListingFloorPlan_ID);
        }
        public IList<Model.ListingFloorPlan> FindByListingID_Language(decimal? listingID, decimal languageFID)
        {
            if (listingID != null)
            {
                var list = (from l in DataContext.ListingFloorPlans
                            where l.ListingFID.Equals(listingID) && l.LanguageFID.Equals(languageFID)
                            orderby l.ListingFloorPlan_ID descending
                            select l).ToList();


                return list.Select(listingFloorPlan => ListingFloorPlanRefactory.FromLINQObject(listingFloorPlan)).ToList();
            }
            return null;
        }
        public Model.ListingFloorPlan FindByID_Language(decimal? ID, decimal languageFID)
        {
            if (ID != null)
            {
                var list = (from l in DataContext.ListingFloorPlans
                            where l.ListingFloorPlan_ID.Equals(ID) && l.LanguageFID.Equals(languageFID)
                            select l).SingleOrDefault();

                return ListingFloorPlanRefactory.FromLINQObject(list);
            }
            return null;
        }
    }
}
